package com.zhou.common.mybatis.template.shiro;

import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.*;
import org.flowable.engine.runtime.ProcessInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;

import java.util.HashMap;
import java.util.Map;

@Slf4j
//@Component
public class BPMNCommandLineRunner2 implements CommandLineRunner {


    @Autowired
    private ProcessEngine processEngine;
    @Override
    public void run(String... args) throws Exception {
        //测试businesskey
        TaskService taskService = processEngine.getTaskService();
        FormService formService = processEngine.getFormService();
        HistoryService historyService = processEngine.getHistoryService();
        RepositoryService repositoryService = processEngine.getRepositoryService();
        RuntimeService runtimeService = processEngine.getRuntimeService();

        Map<String, Object> variables = new HashMap<String, Object>();
        //设置审批人
        variables.put("input1", "xianfeng");
        int[] test1={1,2,3,4,5};
        variables.put("inputArray", test1);
        variables.put("myarray", test1);
//        variables.put("inputArray ", Lists.newArrayList(1,2,3,4,5));
/*        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("test3",  variables);
        log.info("processInstance={}",processInstance);
        Task task = taskService.createTaskQuery().taskAssignee("xianfeng").singleResult();
        log.info("task={}",task);*/

        int[] inputArray = new int[] { 1, 2, 3, 4, 5 };
        Map<String, Object> variables1 =new HashMap();
        variables1.put("inputArray", inputArray);
/*        CollectionUtil.singletonMap("inputArray", inputArray);
//        ProcessInstance pi = runtimeService.startProcessInstanceByKey("test3", CollectionUtil.singletonMap("inputArray", inputArray));
        ProcessInstance pi = runtimeService.startProcessInstanceByKey("test3", CollectionUtil.singletonMap("inputArray", inputArray));*/
        ProcessInstance pi = runtimeService.startProcessInstanceByKey("test3", variables1);





        Map<String,Object> map=new HashMap<>();
        map.put("inputArray", inputArray);
        map.put("test11", "inputArray");
        ProcessInstance pi1 = runtimeService.startProcessInstanceByKey("test3", map);
        String result = (String) runtimeService.getVariable(pi.getId(), "a");
        Integer sum = (Integer) runtimeService.getVariable(pi.getId(), "sum");
    }
}
